home *** CD-ROM | disk | FTP | other *** search
/ Software 2000 / Software 2000 Volume 1 (Disc 1 of 2).iso / utilities / u118.dms / in.adf / iff / unpacker.c < prev   
Encoding:
C/C++ Source or Header  |  1990-11-30  |  2.2 KB  |  69 lines

  1. /*----------------------------------------------------------------------*
  2.  * unpacker.c Convert data from "cmpByteRun1" run compression. 11/15/85
  3.  *
  4.  * By Jerry Morrison and Steve Shaw, Electronic Arts.
  5.  * This software is in the public domain.
  6.  *
  7.  *    control bytes:
  8.  *     [0..127]   : followed by n+1 bytes of data.
  9.  *     [-1..-127] : followed by byte to be repeated (-n)+1 times.
  10.  *     -128       : NOOP.
  11.  *
  12.  * This version for the Commodore-Amiga computer.
  13.  *----------------------------------------------------------------------*/
  14. #include "iff/packer.h"
  15.  
  16.  
  17. /*----------- UnPackRow ------------------------------------------------*/
  18.  
  19. #define UGetByte()    (*source++)
  20. #define UPutByte(c)    (*dest++ = (c))
  21.  
  22. /* Given POINTERS to POINTER variables, unpacks one row, updating the source
  23.  * and destination pointers until it produces dstBytes bytes. */
  24. BOOL UnPackRow(pSource, pDest, srcBytes0, dstBytes0)
  25. #ifdef NORTHC
  26.     /* NorthC casts all function arguments into 4 byte integers, 
  27.            unfortunately it does not compile short arguments to take 
  28.            account of this, so any function with short arguments will 
  29.            get a stack alignment problem */
  30.     BYTE **pSource, **pDest;  int srcBytes0, dstBytes0; {
  31. #else
  32.     BYTE **pSource, **pDest;  WORD srcBytes0, dstBytes0; {
  33. #endif
  34.     register BYTE *source = *pSource;
  35.     register BYTE *dest   = *pDest;
  36.     register WORD n;
  37.     register BYTE c;
  38.     register WORD srcBytes = (WORD)srcBytes0, dstBytes = (WORD)dstBytes0;
  39.     BOOL error = TRUE;    /* assume error until we make it through the loop */
  40.     WORD minus128 = -128;  /* get the compiler to generate a CMP.W */
  41.  
  42.     while( dstBytes > 0 )  {
  43.     if ( (srcBytes -= 1) < 0 )  goto ErrorExit;
  44.         n = UGetByte();
  45.  
  46.         if (n >= 0) {
  47.         n += 1;
  48.         if ( (srcBytes -= n) < 0 )  goto ErrorExit;
  49.         if ( (dstBytes -= n) < 0 )  goto ErrorExit;
  50.         do {  UPutByte(UGetByte());  } while (--n > 0);
  51.         }
  52.  
  53.         else if (n != minus128) {
  54.         n = -n + 1;
  55.         if ( (srcBytes -= 1) < 0 )  goto ErrorExit;
  56.         if ( (dstBytes -= n) < 0 )  goto ErrorExit;
  57.         c = UGetByte();
  58.         do {  UPutByte(c);  } while (--n > 0);
  59.         }
  60.     }
  61.     error = FALSE;    /* success! */
  62.  
  63.   ErrorExit:
  64.  
  65.     *pSource = source;  *pDest = dest;
  66.     return(error);
  67.     }
  68.  
  69.